package com.darrenchan.leetcode;

import java.util.Stack;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2020-03-08 14:51
 */
public class MinStack {
    Stack<Integer> stack;
    Stack<Integer> stackMin;

    public MinStack() {
        stack = new Stack<>();
        stackMin = new Stack<>();
    }

    /*
     * @param number: An integer
     * @return: nothing
     */
    public void push(int number) {
        stack.push(number);
        if(stackMin.isEmpty()) {
            stackMin.push(number);
        } else {
            stackMin.push(Math.min(number, stackMin.peek()));
        }
    }

    /*
     * @return: An integer
     */
    public int pop() {
        stackMin.pop();
        return stack.pop();
    }

    /*
     * @return: An integer
     */
    public int min() {
        return stackMin.peek();
    }
}
